package com.example.export_data.mapper;

import com.example.export_data.bean.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

public interface UserJpa extends JpaRepository<User, Long>, JpaSpecificationExecutor<User>, Serializable {

    @Modifying
    @Transactional
    @Query(value = "update ums_imall_user set user_status = '0',audit_status = 'del' where wid = :wid", nativeQuery = true)
    void delUser(@Param("wid") Long wid);

    @Modifying
    @Transactional
    @Query(value = "update ums_imall_user set unionid = :unionid where oa_openid = :oa_openid", nativeQuery = true)
    void updateUserByOaOpenId(@Param("unionid") String unionid,@Param("oa_openid") String oa_openid);

    @Modifying
    @Transactional
    @Query(value = "update ums_imall_user set unionid = :unionid where openid = :openid", nativeQuery = true)
    void updateUserByOpenId(@Param("unionid") String unionid,@Param("openid") String openid);

    @Query(value = "select oa_openid from ums_imall_user where oa_openid <> '' and openid = '' and user_status = 1",nativeQuery = true)
    List<String> getOaOpenUsers();

    @Query(value = "select openid from ums_imall_user where openid <> '' and user_status = 1",nativeQuery = true)
    List<String> getOpenUsers();

}
